home *** CD-ROM | disk | FTP | other *** search
- *******************************************************************************
- * PROGRAM: Paint.wfm
- *
- * WRITTEN BY: Borland Samples Group
- *
- * DATE: 4/94
- *
- * UPDATED: 5/95
- *
- * REVISION: $Revision: 1.5 $
- *
- * VERSION: Visual dBASE
- *
- * DESCRIPTION: This program demonstrates the use of the paintbox and shapes
- * controls by allowing you to select an image from a table or
- * from a .bmp file, and combine it with an existing/previous
- * image.
- *
- * PARAMETERS: None
- *
- * CALLS: Buttons.cc (Custom Controls file)
- *
- * USAGE: DO Paint.wfm
- *
- ********************************************************************************
- #include <winapi.h>
- #define NUM_RASTER_OPS 6
-
- *** Environment
- create session
- set talk off
- set fullpath off
-
- ** END HEADER -- do not remove this line*
- * Generated on 07/18/95
- *
- parameter bModal
- local f
- f = new PAINTFORM()
- if (bModal)
- f.mdi = .F. && ensure not MDI
- f.ReadModal()
- else
- f.Open()
- endif
- CLASS PAINTFORM OF FORM
- Set Procedure To BUTTONS.CC additive
- this.OnOpen = CLASS::FORM_ONOPEN
- this.OnClose = CLASS::FORM_ONCLOSE
- this.Text = "Image Painter"
- this.OnNavigate = CLASS::FORM_ONNAVIGATE
- this.Top = 0.2344
- this.Left = 15
- this.OnSize = CLASS::FORM_ONSIZE
- this.ColorNormal = "N/BTNFACE"
- this.Height = 17.7051
- this.Width = 58.666
-
- DEFINE SHAPE SHAPE1 OF THIS;
- PROPERTY;
- ShapeStyle 0,;
- Top 0.5,;
- PenWidth 1,;
- Left 1,;
- ColorNormal "B/BTNFACE",;
- Height 4.3232,;
- Width 57
-
- DEFINE SHAPE RADIOSHAPE OF THIS;
- PROPERTY;
- Visible .F.,;
- ShapeStyle 2,;
- Top 1.6973,;
- PenWidth 2,;
- Left 7,;
- ColorNormal "B/BTNFACE",;
- Height 1.7139,;
- Width 12
-
- DEFINE LINE LINE1 OF THIS;
- PROPERTY;
- Top 5.4,;
- Bottom 5.4,;
- Right 2,;
- Left 57,;
- ColorNormal "GB+/BTNFACE",;
- Width 1
-
- DEFINE LINE LINE2 OF THIS;
- PROPERTY;
- Top 5.6065,;
- Bottom 5.6065,;
- Right 3,;
- Left 55.6065,;
- ColorNormal "RG+/BTNFACE",;
- Width 1
-
- DEFINE LINE LINE3 OF THIS;
- PROPERTY;
- Top 5.8529,;
- Bottom 5.8529,;
- Right 4.3333,;
- Left 53.6667,;
- ColorNormal "B+/BTNFACE",;
- Width 1
-
- DEFINE SHAPE OPERATIONSHAPE OF THIS;
- PROPERTY;
- ShapeStyle 0,;
- Top 6.5,;
- PenWidth 1,;
- Left 1.8311,;
- ColorNormal "B/BTNFACE",;
- Height 2.0293,;
- Width 55.002
-
- DEFINE SHAPE SRCSHAPE OF THIS;
- PROPERTY;
- ShapeStyle 0,;
- Top 9.5293,;
- PenWidth 1,;
- Left 2.1982,;
- ColorNormal "B/BTNFACE",;
- Height 5.8818,;
- Width 23.6348
-
- DEFINE SHAPE DSTSHAPE OF THIS;
- PROPERTY;
- ShapeStyle 0,;
- Top 9.5293,;
- PenWidth 1,;
- Left 33,;
- ColorNormal "B/BTNFACE",;
- Height 5.8818,;
- Width 23.666
-
- DEFINE TEXT SELECTTEXT OF THIS;
- PROPERTY;
- FontItalic .T.,;
- Text "Select Source Bitmap: ",;
- Top 0.1875,;
- Left 19,;
- ColorNormal "B+/BTNFACE",;
- Height 0.7529,;
- Width 18.5,;
- FontBold .F.
-
- DEFINE TOOLBUTTON IMAGETOOLBUTTON OF THIS;
- PROPERTY;
- Group .F.,;
- OnClick CLASS::SELECTBINARY,;
- Top 1.8223,;
- Left 2.5,;
- Height 1.2949,;
- Width 4
-
- DEFINE RADIOBUTTON BINARYRADIO OF THIS;
- PROPERTY;
- Group .T.,;
- Text "Binary",;
- OnChange CLASS::BINARYRADIO_ONCHANGE,;
- Top 2.0977,;
- Left 8.5,;
- Value .T.,;
- ColorNormal "B/BTNFACE",;
- Height 0.8428,;
- Width 9,;
- FontBold .F.
-
- DEFINE RADIOBUTTON FILERADIO OF THIS;
- PROPERTY;
- Group .F.,;
- Text "File",;
- OnChange CLASS::FILERADIO_ONCHANGE,;
- Top 3.3975,;
- Left 8.5,;
- Value .F.,;
- ColorNormal "B/BTNFACE",;
- Height 0.8965,;
- Width 7,;
- FontBold .F.
-
- DEFINE TEXT FIELDNAMETEXT OF THIS;
- PROPERTY;
- FontItalic .T.,;
- Text "Field Name:",;
- Top 1.1973,;
- Left 20,;
- ColorNormal "N+/BTNFACE",;
- Height 0.8027,;
- Width 12.5,;
- FontBold .F.
-
- DEFINE COMBOBOX FIELDNAMECOMBO OF THIS;
- PROPERTY;
- OnOpen CLASS::FIELDNAMECOMBO_ONCHANGE,;
- FontSize 7,;
- OnChange CLASS::FIELDNAMECOMBO_ONCHANGE,;
- Top 2,;
- Style 1,;
- Left 20,;
- ColorNormal "B/GB+",;
- Height 1,;
- FontName "MS Serif",;
- Width 22,;
- FontBold .F.
-
- DEFINE TEXT RECNOTEXT OF THIS;
- PROPERTY;
- FontItalic .T.,;
- Text "Record No: ",;
- Top 1.1973,;
- Left 45,;
- ColorNormal "N+/BTNFACE",;
- Height 0.8027,;
- Width 11.5,;
- FontBold .F.
-
- DEFINE SPINBOX RECNOSPIN OF THIS;
- PROPERTY;
- Rangemax 100,;
- OnChange CLASS::RECNOSPIN_ONCHANGE,;
- Top 2,;
- Left 45,;
- Value 1,;
- Rangemin 1,;
- ColorNormal "B/GB+",;
- Picture "9999",;
- Height 1,;
- RangeRequired .T.,;
- FontName "MS Serif",;
- Width 11
-
- DEFINE ENTRYFIELD FILEENTRY OF THIS;
- PROPERTY;
- Visible .F.,;
- Top 3.3975,;
- Enabled .F.,;
- Left 20,;
- Value "",;
- ColorNormal "B/GB+",;
- Height 1.0137,;
- Width 36
-
- DEFINE TEXT OPERATIONTEXT OF THIS;
- PROPERTY;
- FontItalic .T.,;
- Text "Raster Operation: ",;
- Top 6.1973,;
- Left 21.5,;
- ColorNormal "B+/BTNFACE",;
- Height 0.7432,;
- Width 15.5,;
- FontBold .F.
-
- DEFINE COMBOBOX RASTEROPCOMBO OF THIS;
- PROPERTY;
- DropDownHeight 4,;
- FontSize 7,;
- ID 102,;
- OnChange CLASS::RASTEROPCOMBO_ONSELCHANGE,;
- Top 7.0977,;
- Style 2,;
- Left 9.3311,;
- ColorNormal "B/GB+",;
- Height 1.0195,;
- FontName "MS Serif",;
- Width 40.002,;
- FontBold .F.
-
- DEFINE TEXT SOURCETEXT OF THIS;
- PROPERTY;
- FontItalic .T.,;
- Text "Source:",;
- Top 9.1973,;
- Left 10,;
- ColorNormal "B+/BTNFACE",;
- Height 0.7432,;
- Width 8.333,;
- FontBold .F.
-
- DEFINE IMAGE SRCIMAGE OF THIS;
- PROPERTY;
- DataSource "",;
- Top 10,;
- Left 4,;
- Height 5,;
- Width 20
-
- DEFINE TEXT DESTINATIONTEXT OF THIS;
- PROPERTY;
- FontItalic .T.,;
- Text "Destination: ",;
- Top 9.1973,;
- Left 40,;
- ColorNormal "B+/BTNFACE",;
- Height 0.7432,;
- Width 11.666,;
- FontBold .F.
-
- DEFINE PAINTBOX DSTPAINTBOX OF THIS;
- PROPERTY;
- OnPaint CLASS::DSTPAINTBOX_ONPAINT,;
- Top 10,;
- Left 35,;
- Height 5,;
- ColorNormal "WindowText/Window",;
- Width 20
-
- DEFINE CLOSEBUTTON CLOSEBUTTON1 OF THIS;
- PROPERTY;
- Group .T.,;
- Top 16,;
- Left 22.1641,;
- Height 1.5293,;
- Width 14.1689,;
- FontBold .F.
-
- DEFINE SAMPLEINFOBUTTON PAINTINFOBUTTON OF THIS;
- PROPERTY;
- Group .T.,;
- Top 16.3975,;
- Left 55,;
- Height 1.1904,;
- Width 3.5
-
- Procedure Form_OnOpen
- ****************************************************************************
-
- * Arrays for describing and executing raster operations
- form.opDescriptAr = new array(NUM_RASTER_OPS) && Raster op descriptions
- form.rasterOpAr = new assocArray() && Raster operations
-
- form.binaryFldAr = new array(0) && Binary field names
-
- form.opDescriptAr[1] = "Copy Source to Destination"
- form.opDescriptAr[2] = "Merge Source with Destination"
- form.opDescriptAr[3] = "Invert Destination"
- form.opDescriptAr[4] = "Copy inverted Source to Destination"
- form.opDescriptAr[5] = "Merge inverted Source with Destination"
- form.opDescriptAr[6] = "Clear out Destination"
-
- form.rasterOpCombo.DataSource = "array form.opDescriptAr"
-
- form.rasterOpAr["Copy Source to Destination"] = SRCCOPY
- form.rasterOpAr["Merge Source with Destination"] = SRCAND
- form.rasterOpAr["Invert Destination"] = DSTINVERT
- form.rasterOpAr["Copy inverted Source to Destination"] = NOTSRCCOPY
- form.rasterOpAr["Merge inverted Source with Destination"] = SRCINVERT
- form.rasterOpAr["Clear out Destination"] = WHITENESS
-
- form.rasterOpCombo.value = form.opDescriptAr[1]
- form.fieldNameCombo.value = "" && Form designer doesn't allow empty value
- form.paintInfoButton.sampleName = "Paint.wfm"
-
- ****************************************************************************
-
- Procedure Form_OnClose
- ****************************************************************************
-
- use && If table had been selected, close it
- close procedure Buttons.cc
-
- ****************************************************************************
-
- Procedure DstPaintBox_Clear
- ****************************************************************************
- private hDcPaintbox, iResult
-
- hDcPaintBox = GetDc(form.dstPaintBox.hWnd) && Paint Box device context
- iResult = BitBlt(hDcPaintBox, 0, 0, 200, 200, 0, 0, 0, WHITENESS) && White
- iResult = ReleaseDc(form.dstPaintBox.hWnd, hDcPaintBox) && Get memory back
-
-
- ****************************************************************************
-
- Procedure DSTPAINTBOX_OnPaint
- ****************************************************************************
- local i, paintStruct
- private hDcPaintbox, hDcImage, hImage, iResult, iRasterOp
-
- * Ensure paint occurs for image source first
- UpdateWindow(form.srcimage.hWnd)
-
- paintStruct = space(32)
- hDC = BeginPaint(this.hwnd, paintStruct)
-
- hImage = form.srcImage.hWnd && Source Image handle
- hDcImage = GetDc(hImage) && Source Image device context
- && Retrieve raster operation
- iRasterOp = form.rasterOpAr[form.rasterOpCombo.value] && Don't use this in
- && case function called from
- && another control
-
- * Do it
- iResult = BitBlt(hDc, 0, 0, 200, 200, hDcImage, 0, 0, iRasterOp)
-
- iResult = ReleaseDc(form.dstPaintBox.hWnd, hDcImage) && Get memory back
-
- EndPaint(paintStruct)
-
- for i = 1 to 1000 && Do some funcky thing
- form.dstShape.penwidth = 3
- form.dstShape.penwidth = 1
- next i
-
-
- ****************************************************************************
-
- Procedure RASTEROPCOMBO_OnSelChange
- ****************************************************************************
-
- invalidateRect (form.dstPaintBox.hwnd, 0, .F. )
-
- ****************************************************************************
-
- Procedure BINARYRADIO_OnChange
- ****************************************************************************
-
- if this.value && If this button is selected
- CLASS::ShowBinaryControls()
- CLASS::ShowFileControls()
-
- form.fieldNameCombo.OnChange() && Enable/disable controls if necessary
- form.imageToolButton.OnClick = CLASS::SelectBinary
- form.imageToolButton.top = 1.832
- endif
-
-
- ****************************************************************************
-
- Procedure FILERADIO_OnChange
- ****************************************************************************
-
- if this.value && If this button is selected
- CLASS::ShowFileControls()
- CLASS::ShowBinaryControls()
-
- form.imageToolButton.OnClick = CLASS::SelectFile
- form.imageToolButton.top = 3.2
- endif
-
- ****************************************************************************
-
- Procedure RECNOSPIN_OnChange
- ****************************************************************************
-
- go this.value && Go to record specified in spinbox
-
-
- ****************************************************************************
-
- Procedure FIELDNAMECOMBO_OnChange
- ****************************************************************************
-
- if empty(this.value) && If no binary fields available,
- this.enabled = .F.
- form.recNoSpin.enabled = .F. && make record selection not available
- else && Otherwise
- this.enabled = .T.
- form.srcImage.dataSource = "binary " + this.value && Update image
- form.recNoSpin.enabled = .T. && Make record selection available
- endif
-
-
- ****************************************************************************
-
- Procedure SelectBinary
- ****************************************************************************
- private tableName, fieldCount, fieldName
-
- tableName = getfile("*.dbf", "Select a table")
- if .not. empty(tableName) && A table was actually selected
- CLASS::ClearFileControls() && Clear out file controls
-
- form.radioShape.top = 1.7
- form.radioShape.visible = .T.
- use (tableName) && Table
- fieldCount = fCount()
- form.binaryFldAr = new array(0)
- for i = 1 to fieldCount
- fieldName = field(i)
- if type(fieldName) = "B" && If Binary field
- form.binaryFldAr.Add(CLASS::GetTableName(dbf()) + "->" + fieldName)
- endif
- next i
- form.fieldNameCombo.value = ""
- form.fieldNameCombo.dataSource = "array form.binaryFldAr"
- * form.fieldNameCombo.visible = .T.
- form.fieldNameCombo.OnChange()
-
- form.recNoSpin.value = 1
- form.recNoSpin.rangeMax = reccount()
- * form.recNoSpin.visible = .T.
- CLASS::ShowBinaryControls()
- endif
-
-
- ****************************************************************************
-
- Procedure SelectFile
- ****************************************************************************
- local fileName
-
- fileName = getFile("*.bmp", "Select a bitmap file")
- if .not. empty(fileName) && If file was actually selected
- CLASS::ClearBinaryControls() && Clear out binary controls
-
- * Set up image from file
- form.radioShape.top = 3 && Move highlight on this radiobutton
- form.radioShape.visible = .T. && Make visible (initially it is not)
- form.fileEntry.value = fileName && Show selected file
- show object form.fileEntry && (Really visible)
- form.srcImage.dataSource = "file " + fileName && Show image in file
- CLASS::ShowFileControls()
- endif
-
-
-
- ****************************************************************************
-
- Function GetTableName(dbf)
- ****************************************************************************
- local strippedName, periodLoc
-
- * Strip drive
- strippedName = substr(dbf, at(":", dbf) + 1)
-
- * Strip extension
- periodLoc = rat(".", strippedName)
- if periodLoc > 0 && dbf has an extension
- strippedName = left(strippedName, periodLoc - 1)
- endif
-
- return strippedName
-
-
- ****************************************************************************
-
- Procedure ShowBinaryControls
- ****************************************************************************
- local notEmptyFieldName
-
- notEmptyFieldName = .not. empty(form.fieldNameCombo.value)
- if form.fileRadio.value && If File radio button is selected
-
- * Only show these controls if they are connected to data
- form.fieldNameText.visible = notEmptyFieldName
- form.fieldNameCombo.visible = notEmptyFieldName
- form.recNoText.visible = notEmptyFieldName
- form.recNoSpin.visible = notEmptyFieldName
-
- * Disable binary selection controls when fileRadio button is selected
- form.fieldNameCombo.enabled = .F.
- form.recNoSpin.enabled = .F.
-
- else && If Binary radio button is selected
- form.fieldNameText.visible = .T.
- form.fieldNameCombo.visible = .T.
- form.recNoText.visible = .T.
- form.recNoSpin.visible = .T.
-
- form.fieldNameCombo.enabled = notEmptyFieldName
- form.recNoSpin.enabled = notEmptyFieldName
-
- endif
-
-
- ****************************************************************************
-
- Procedure ClearBinaryControls
- ****************************************************************************
-
- * Make controls invisible
- form.fieldNameText.visible = .F.
- form.fieldNameCombo.visible = .F.
- form.recNoText.visible = .F.
- form.recNoSpin.visible = .F.
-
- * Clear out values
- form.fieldNameCombo.dataSource = ""
- form.fieldNameCombo.value = ""
- form.recNoSpin.value = 1
-
- * Close table, if it is open
- use
-
-
- ****************************************************************************
-
- Procedure ShowFileControls
- ****************************************************************************
- private notEmptyFileName
-
- notEmptyFileName = .not. empty(form.fileEntry.value)
- if form.binaryRadio.value && If Binary radio button is selected
- form.fileEntry.visible = notEmptyFileName
- else && If File radio button is selected
- form.fileEntry.visible = .T.
- endif
- show object form.fileEntry
-
-
- ****************************************************************************
-
- Procedure ClearFileControls
- ****************************************************************************
-
- form.fileEntry.visible = .F.
- form.fileEntry.value = ""
-
-
- ****************************************************************************
-
- Procedure Form_OnSize(sizeType, width, height)
- ****************************************************************************
-
- form.height = 17.71
- form.width = 58.67
-
- Procedure Form_OnNavigate(nWorkArea)
- invalidateRect (form.dstPaintBox.hwnd, 0, .F. )
-
- ENDCLASS
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-